package com.daykw.wkinfo.task;

import java.util.List;
import java.util.concurrent.ExecutorService;

import org.apache.log4j.Logger;
import org.nutz.dao.Cnd;
import org.nutz.dao.impl.NutDao;

import com.daykw.wkinfo.config.NutzDaoConfig;
import com.daykw.wkinfo.model.ArticleTask;
import com.daykw.wkinfo.utils.SpringContextHolder;
import com.daykw.wkinfo.utils.ThreadPools;

public class ArticleHtmlJob implements Runnable {

	private static Logger logger = Logger.getLogger(ArticleHtmlJob.class);

	@Override
	public void run() {
		java.util.Random random = new java.util.Random();
		int r = random.nextInt(100);
		NutDao dao = SpringContextHolder.getBean(NutzDaoConfig.class);
		List<ArticleTask> list = dao.query(ArticleTask.class, Cnd.wrap("status=0 and  mod(id,100)=" + r + " limit 1"));
		ExecutorService pool = ThreadPools.getThreadPool("ArticleHtmlJob", 1);
		for (ArticleTask task : list) {
			try {
			
				ArticleHtmlThread t = new ArticleHtmlThread(task);
				pool.execute(t);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		logger.info("执行完抓取文章详情");

	}

}
